home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
clp.exe
/
D.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-09-07
|
7KB
|
228 lines
{ ========================================================================= }
{ }
{ }
{ !!!!! !!!!!! }
{ !! !! !! !! }
{ !! !! !! !! !!!! !!!!! }
{ !! !! !! !! !! !! !! }
{ !! !! !!!!! !!!!! !!! }
{ !! !! !! !! !! !!! }
{ !! !! !! !! !! !! !! !! }
{ !!!!! !! !!!! !!! !! !!!!! }
{ }
{ CLParser v3.20 CARGO Demo }
{ }
{ ========================================================================= }
{ Copyright (c) 1989,1992 Greg Truesdell }
{ ========================================================================= }
Program Directory;
Uses
{ !! THIS SAMPLE FILE REQUIRES OBJECT PROFESSIONAL TO COMPILE !! }
OpCrt, OpDate, OpString,
Dos,
CLParser;
{ ========================================================================= }
{ G L O B A L D E C L A R A T I O N S }
{ ========================================================================= }
Type
String80 = String[80];
String4 = String[4];
Const
QuietMode : Boolean = FALSE; { quiet mode operation }
DefPath : String80 = '*.*';
Var
pArg : pArgument; { arguments }
pSw : pArgument; { switches }
pDir : pWild; { directory list }
{ ========================================================================= }
{ E R R O R E X I T }
{ ========================================================================= }
Procedure ErrorExit( msg : String80 );
begin
WriteLn( msg );
Halt(1);
end;
{ ========================================================================= }
{ I N I T I A L I Z E }
{ ========================================================================= }
Procedure Initialize;
var
sw : String80;
ii : Word;
begin
{ initialize the command line objects }
pArg := New( pArgument, Init( NormalChars-Switches ) );
pSw := New( pArgument, Init( Switches ) );
if (pArg=Nil) or (pSw=Nil) then
ErrorExit('Commandline init failure: Not enough memory!');
{ begin parsing switches }
if pSw^.Count > 0 then with pSw^ do for ii := 1 to Count do
begin
sw := ' ';
sw := Next;
case UpCase(sw[2]) of
'Q' : { Quiet Mode }
QuietMode := True;
'R' : { redirect output }
begin
Assign(OutPut,'');
ReWrite(OutPut);
end;
end;
end;
{ parse filenames etc }
if pArg^.Count > 0 then with pArg^ do
begin
DefPath := Next;
if JustFilename(DefPath) = '' then
DefPath := DefPath + '*.*';
end;
{ free memory }
Dispose( pSw, Done );
Dispose( pArg, Done );
end;
{ ========================================================================= }
{ C O N V E R T D A T E }
{ ========================================================================= }
Function ConvertDate( Julian : Date ) : String80;
var
dt : DateTime;
dTime : Time;
dDate : Date;
begin
UnPackTime( Julian, dt );
with dt do
begin
dTime := HMStoTime( Hour, Min, Sec );
dDate := DMYtoDate( Day, Month, Year );
end;
ConvertDate := DateToDateString( 'mm-dd-yy', dDate ) + ' ' +
TimeToTimeString( 'HH:mm:sst', dTime );
end;
{ ========================================================================= }
{ C O N V E R T A T T R I B U T E }
{ ========================================================================= }
Function ConvertAttr( Attr : Byte ) : String4;
var
st : String4;
begin
st := '____';
if (Attr and Archive) > 0 then st[1] := 'A';
if (Attr and Hidden) > 0 then st[2] := 'H';
if (Attr and ReadOnly) > 0 then st[3] := 'R';
if (Attr and SysFile) > 0 then st[4] := 'S';
ConvertAttr := st;
end;
{ ========================================================================= }
{ D I R E C T O R Y L I S T }
{ ========================================================================= }
Procedure DirectoryList( dpath : String );
var
Filename : String80;
pSR : ^SearchRec;
SRLen : LongInt;
ii : Word;
begin
{ initialize the wildcard object }
{ ======================================================== }
{ }
{ NOTE: The pWild object calls the AddCargo method using }
{ the search record returned by the FindFirst() and }
{ FindNext() DOS unit procedures. }
{ }
{ ======================================================== }
pDir := New( pWild, Init( dpath, AnyFile-VolumeID ) );
{ allocate space for the Search Record }
GetMem( pSR, SizeOf(SearchRec) );
if (pDir <> Nil) and (pSR <> Nil) then with pDir^ do
begin
WriteLn('Directory for ' + fExpand(DefPath) );
for ii := 1 to Count do
begin
{ get next filename and file info (as cargo) }
Filename := NextCargo( Pointer(pSR), SRLen );
{ display a directory line }
if (pSR^.Attr and Dos.Directory) = 0 then
WriteLn( Filename:16, pSR^.Size:8,' ',
ConvertAttr( pSR^.Attr ), ' ', ConvertDate( pSR^.Time ) )
else if (pSR^.Attr and VolumeID) = 0 then
WriteLn( StLoCase(Filename):16, '<DIR>':8,' ',
ConvertAttr( pSR^.Attr ), ' ', ConvertDate( pSR^.Time ) )
end;
end;
end;
{ ========================================================================= }
{ M A I N }
{ ========================================================================= }
Begin
Initialize;
DirectoryList( DefPath );
End.
{ ========================================================================= }
{ E O F }
{ ========================================================================= }